package cz.data.domain.system.model.vo;

import com.fasterxml.jackson.annotation.JsonProperty;
import cz.data.common.core.DataRole;
import cz.data.common.core.DataUser;
import cz.data.common.core.OAuth2Token;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class LoginUserInfoVo {

    @JsonProperty("access_token")
    private String accessToken;
    private String username;
    private String nickname;
    @JsonProperty("user_id")
    private String userId;
    @JsonProperty("user_dept")
    private String dept;
    @JsonProperty("user_post")
    private List<String> post;
    @JsonProperty("user_role")
    private List<DataRole> roles;

    public static LoginUserInfoVo form(OAuth2Token token, DataUser user) {
        return LoginUserInfoVo.form(token.getAccessToken(), user);
    }

    public static LoginUserInfoVo form(String token, DataUser user) {
        LoginUserInfoVo vo = new LoginUserInfoVo();
        vo.setAccessToken(token);
        vo.setUsername(user.getUsername());
        vo.setNickname(user.getNickname());
        vo.setUserId(user.getId());
        vo.setDept(user.getDept());
        vo.setPost(user.getPosts());
        vo.setRoles(user.getRoles());
        return vo;
    }
}
